package com.myzl.coal.service.protocol.impl;

import com.myzl.coal.dto.CmdDTO;
import com.myzl.coal.service.protocol.SievePlcCmdService;
import com.myzl.coal.service.protocol.CmdService;
import com.myzl.common.enums.DeviceCommandEnum;
import com.myzl.common.enums.DeviceTypeEnum;
import com.myzl.common.enums.PlcWriteEnum;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collections;

/**
 * @ClassName BoXuanPlcCmdServiceImpl
 * @Author wzb
 * @Date 2023/6/7 9:36
 * @Description
 */
@Service
@Slf4j
@Data
public class SievePlcCmdServiceImpl implements SievePlcCmdService {
    private final CmdService cmdService;

    @Override
    public void getAll(Integer deviceId) {
        CmdDTO cmdDTO = new CmdDTO();
        cmdDTO.setDeviceType(DeviceTypeEnum.SIEVE_PLC.getCode());
        cmdDTO.setDeviceId(deviceId);
        cmdDTO.setAddress(DeviceCommandEnum.SIEVE_PLC_ALL.getCode());
        cmdDTO.setRemark(DeviceCommandEnum.SIEVE_PLC_ALL.getInfo());
        cmdDTO.setCount(DeviceCommandEnum.SIEVE_PLC_ALL.getNumber());
        cmdService.read(cmdDTO);
    }

    @Override
    public void getAddressZero(Integer deviceId) {
        CmdDTO cmdDTO = new CmdDTO();
        cmdDTO.setDeviceType(DeviceTypeEnum.SIEVE_PLC.getCode());
        cmdDTO.setDeviceId(deviceId);
        cmdDTO.setAddress(DeviceCommandEnum.SIEVE_PLC_POLICE.getCode());
        cmdDTO.setRemark(DeviceCommandEnum.SIEVE_PLC_POLICE.getInfo());
        cmdDTO.setCount(DeviceCommandEnum.SIEVE_PLC_POLICE.getNumber());
        cmdService.read(cmdDTO);
    }

    @Override
    public void stop(Integer deviceId) {
        CmdDTO cmdDTO = new CmdDTO();
        cmdDTO.setDeviceType(DeviceTypeEnum.SIEVE_PLC.getCode());
        cmdDTO.setDeviceId(deviceId);
        cmdDTO.setAddress(DeviceCommandEnum.SIEVE_PLC_STOP.getCode());
        cmdDTO.setRemark(DeviceCommandEnum.SIEVE_PLC_STOP.getInfo());
        cmdDTO.setData(Collections.singletonList(PlcWriteEnum.YES.getCode()));
        cmdService.write(cmdDTO);
    }
}
